package controller;

import org.junit.Test;
import util.DBTools;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestDemo {
    @Test
    public void test(){
        //创建连接
        Connection connection = DBTools.getConnection();
        //执行sql
        String sql= "select * from user";
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps=connection.prepareStatement(sql);
            //获取结果集
            rs = ps.executeQuery();
            while (rs.next()){
                System.out.println(rs.getString("username")+"--"+rs.getString("nickname"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {

            //释放资源
            DBTools.close(connection,ps,rs);

        }

    }
}
